//
//  XJYMTTieziDetailBottomView.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/6/6.
//  Copyright © 2018年 Tzyang. All rights reserved.
//  有名堂 帖子底部view(点赞按钮 + 评论按钮)


#import "XJYMTTieziDetailBottomView.h"
@interface XJYMTTieziDetailBottomView()
@property(nonatomic, strong) UIView *bgView;
@property(nonatomic, strong) UIButton *starButton; // 点赞按钮
@property(nonatomic, strong) UIButton *commentButton; // 评论按钮

@end

@implementation XJYMTTieziDetailBottomView


#pragma mark - 一 初始化
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupView];
    }
    return self;
}
- (void)setupView {
    [self addSubview:self.bgView];
    [self.bgView addSubview:self.starButton];
    [self.bgView addSubview:self.commentButton];
}

#pragma mark - 二 lazy
- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [UIView new];
    }
    return _bgView;
}
- (UIButton *)starButton {
    if (!_starButton) {
        _starButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        UIImage *image = [UIImage imageNamed:@"goods_shoucang_on"];
        UIImage *selectedImge = [UIImage  imageNamed:@"goods_shoucang_off"];
        
        [_starButton setImage:image forState:(UIControlStateNormal)];
        [_starButton setImage:selectedImge forState:(UIControlStateSelected)];
        [_starButton addTarget:self action:@selector(satrButtonACtion:) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _starButton;
}

- (UIButton *)commentButton {
    if (!_commentButton) {
        _commentButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_commentButton setImage:[UIImage imageNamed:@"nav_message"] forState:(UIControlStateNormal)];
        [_commentButton setTitle:@"评论" forState:(UIControlStateNormal)];
        [_commentButton setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
        [_commentButton addTarget:self action:@selector(commentButonAction) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _commentButton;
}


#pragma mark - 三 layout
- (void)layoutSubviews {
    [super layoutSubviews];
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    [self.starButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bgView.mas_left).offset(50);
        make.centerY.equalTo(self.bgView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];
    
    [self.commentButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.bgView.mas_right).offset(-50);
        make.centerY.equalTo(self.bgView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(100, 40));
    }];
}

#pragma mark - 四 事件回调
- (void)satrButtonACtion:(UIButton *)button {
    XJLog(@"点赞");
    button.selected = !button.selected;
    
    //网络请求就在这里写吧。
    
    if([NSString isEmptyString:self.tieId]) return;
    
    [XJHttpTool requestInvitationColllectionCollectionWithInvitation_id:self.tieId successH:^(id responseObjc) {
        
    } failH:^(NSError *error) {
        
    }];
}





- (void)commentButonAction{
    if (self.clickCommentButtonBlock) {
        self.clickCommentButtonBlock();
    }
}

#pragma mark - dealloc
- (void)dealloc {
    XJLog(@"销毁了");
}


@end
